package com.bsoft.springboot2_7;

import com.bsoft.utils.GmCryptoUtils;
import com.bsoft.utils.HttpClientUtil;
import com.bsoft.utils.JSONUtil;
import com.bsoft.utils.XmlMapUtils;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.ObjectUtils;
import sun.misc.BASE64Decoder;

import java.io.FileWriter;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

@SpringBootTest
public class test {

    public static void main(String[] args) throws Exception {

       /* String res = "eyJtZXNzYWdlIjoiNksrMzVyR0M1WStDNXBXd1czQnNZV05sUTI5a1pTamx2SURucGFqbmdybm52SmJub0lFcExPV0F2Q2h6ZVhNd01TbGQ1cmlGNXJTWDVieUM1Ymk0Nzd5YTVZMlY1TDJONWErNTU0V241cWloNXAyL1crV1BqT2FmaitXT3YrUzZ1dWF3a2VXTXUrbVpvbDNtaWI3a3VJM2xpTERsdklEbnBham5ncmxiYzNsek1ERmQ1YSs1NTRXbkxDQjBjbUZqWlVsa09pQTJZVFF6TmpWbU5UZGxNVGMwWm1ZM1ltWmhOVEkyWW1GbU9UZzRZamM0TXk0eE9ESXlPVE0zTGpFM01qTTVOekF6TkRrd09UTXdOekV4IiwicmVzdWx0IjoiOTk5OTkifQ==";
        String s = BASE64Decrypt(res);
        System.out.println("返回加密信息1::"+s); //生产者  消费者

        Map<String, Object> map = JSONUtil.toHashMap(s);
        String message = BASE64Decrypt(map.get("message").toString());

        System.out.println("返回加密信息2::"+message);*/

       /* String res = "{\n" +
                "    \"data\": \"eyJtZXNzYWdlIjoiZXlKeVlXNWtiMjBpT2lKa05UQmpOV1FpTENKamNtVmhkR1ZVYVcxbElqb2lNakF5TkRBNE1UZ3hPVEUxTlRFMk9EUWlMQ0p3YVdOMGRYSmxWWEpzSWpvaWF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    \"noise\": \"bf1adbd46fdd4ecea2f98e20d7bbb352\",\n" +
                "    \"sign\": \"CA6A547C80A789F9231E037A5E3C3A2E\"\n" +
                "}";

        Map<String, Object> resMap = JSONUtil.toHashMap(res);
        if (!ObjectUtils.isEmpty(resMap)){
            String data = (String) resMap.get("data");
            data = BASE64Decrypt(data);

            Map<String, Object> dataMap = JSONUtil.toHashMap(data);
            if ("S0000".equals(dataMap.get("result").toString())){
                String messageStr = dataMap.get("message").toString();
                messageStr = BASE64Decrypt(messageStr);
                System.out.println(messageStr);
                Map<String, Object> messageMap = JSONUtil.toHashMap(messageStr);
            }
        }

*/
        String url ="http://10.190.122.119:30079/idc-basic-api-xinjin/openapi/v1/his/hospital-redirect-to-icd-admin";
        Map map = new HashMap<>();
        map.put("job_number","hMnvBhPkEr01105231607592");
        map.put("hid","4492");
        map.put("center_code","COPD");
        map.put("route_name","Upcoming");

        Map<String, Object> headerMap = new HashMap<>();
        headerMap.put("Content-Type", "application/json");

        Map<String, Object> s = HttpClientUtil.sendPostByJson(url, headerMap, map, StandardCharsets.UTF_8);
        System.out.println("专病接口:"+s);
    }

    /**BASE64解密*/
    public static String BASE64Decrypt(String json) throws IOException {
        BASE64Decoder base64Decoder =  new BASE64Decoder();
        byte[] data = base64Decoder.decodeBuffer(json.toString());//解密
        String byteToText = new String(data, "UTF-8");
        return byteToText;
    }



    @Test
    public void StreamTest(){
        //1.map() 将流中的每个元素映射到另一个元素，通常用于数据转换
        List<String> words = Arrays.asList("apple", "banana", "cherry");
        Map<String, Object> wordCountMap = words.stream().collect(Collectors.toMap(Function.identity(), s -> s.length())); // 每个单词的计数为1
        Map<String, Object> wordCountMap1 = words.stream().collect(Collectors.toMap(Function.identity(), s -> s)); // 每个单词的计数为1
        Map<Character, List<String>> byFirstChar = words.stream().collect(Collectors.groupingBy(s -> s.charAt(0)));

        List<String> upperCaseWords = words.stream() .map(String::toUpperCase) .collect(Collectors.toList());
        //2.filter()通过提供的谓词（Predicate）对流中的元素进行过滤，只保留满足条件的元素。
        List<String> longWords = words.stream() .filter(w -> w.length() > 3) .collect(Collectors.toList());
        //3.reduce() 对流中的元素进行归约操作，如求和、求最大值等 ,计算字符串列表中所有单词的长度之和
        int sumOfLengths = words.stream().mapToInt(String::length).reduce(0, Integer::sum);
        //5.collect() 将流中的元素收集到一个结果容器（如List、Set、Map）中，或者进行其他形式的汇总操作。
        List<String> collectedWords = words.stream().collect(Collectors.toList());
        //6.sorted()对流中的元素进行排序。
        List<String> sortedWords = words.stream().sorted().collect(Collectors.toList());
        //7.limit() 限制流中的元素数量。获取字符串列表中的前两个元素。
        List<String> firstTwoWords = words.stream().limit(2).collect(Collectors.toList());
        //8.skip()跳过流中的前n个元素,跳过字符串列表中的前两个元素
        List<String> skippedWords = words.stream().skip(2).collect(Collectors.toList());
        //9.anyMatch(), allMatch(), noneMatch() 检查流中的元素是否满足某个条件 检查是否有长度大于3的单词。
        boolean hasLongWords = words.stream().anyMatch(w -> w.length() > 3);
        //10.count() 计算流中元素的数量 计算字符串列表中的单词数量。
        long wordCount = words.stream().count();
        //11.forEach() 对流中的每个元素执行某个操作。 打印字符串列表中的所有单词。
        words.stream().forEach(System.out::println);
    }





}

